package com.xzq.socket.test.day01.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.charset.Charset;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/19 9:00
 * @Version 1.0.0
 **/
public class NioServer {
    public static void main(String[] args) {
        new NioServer().lister(9999);
    }

    private void lister(int i) {
        try {
            Selector selector = Selector.open();
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ssc.register(selector, SelectionKey.OP_ACCEPT);
            ssc.bind(new InetSocketAddress(i));
            new NioServerHandler(selector, Charset.forName("gbk")).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
